package com.hualan.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.mapper.QuestionsMapper;
import com.hualan.pojo.PageResult;
import com.hualan.pojo.Questions;

import com.hualan.pojo.SysUser;
import com.hualan.service.QuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Component
public class QuestionServiceImpl implements QuestionsService {

    @Autowired
    private QuestionsMapper questionsMapper;


    //查询所有问题
    @Override
    public PageResult<Questions> getAllActiveQuestions(Integer page, Integer pageSize) {

        PageHelper.startPage(page, pageSize);
        List<Questions> questionsList = questionsMapper.selectAllActive();

        Page<Questions> p=(Page<Questions>)questionsList;
        return new PageResult<>(p.getTotal(),p.getResult());
    }
    //删除单条问题
    @Override
    @Transactional
    public int deleteByPrimaryKey(Long id) {
        return questionsMapper.deleteByPrimaryKey(id);
    }
    //批量删除问题
    @Override
    @Transactional
    public int batchDelete(List<Long> ids) {
        return questionsMapper.batchDelete(ids);
    }

    //新增问题
    @Override
    @Transactional
    public int insertQuestion(Questions questions) {
        return questionsMapper.insert(questions);
    }

    //标题模糊查询
    @Override
    public PageInfo<Questions> selectByTitle(String title, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Questions> questionsList = questionsMapper.selectByTitle(title);
        return new PageInfo<>(questionsList);
    }

    @Override
    public Questions selectByPrimaryKey(Long id) {
        return questionsMapper.selectByPrimaryKey(id);
    }

}
